/*
 ============================================================================
 Name        : BitStream.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CBitStream implementation
 ============================================================================
 */

#include "BitStream.h"
#include "Global.h"
#define	BITSTREAMCONST	(CGlobal::Static()->g_BitStreamConst)
TBitCode::TBitCode(TInt16 wCodeBits, TInt8 cCodeLen, TInt8 cDataType, TInt8 cDataLen,
    TInt dwDataBias):
    m_wCodeBits(wCodeBits), 
    m_cCodeLen(cCodeLen), 
    m_cDataType(cDataType), 
    m_cDataLen(cDataLen),
    m_dwDataBias(dwDataBias)
{
}

CBitStreamConst::CBitStreamConst()
{
}

CBitStreamConst::~CBitStreamConst()
{
    BC_DYNA_TIMEDIFF.ResetAndDestroy();
    BC_DYNA_PRICE_DIFF.ResetAndDestroy();
    BC_DYNA_PRICE_DIFFS.ResetAndDestroy();
    BC_DYNA_VOL.ResetAndDestroy();
    BC_DYNA_VOL_DIFF.ResetAndDestroy();
    BC_DYNA_VOL_DIFFS.ResetAndDestroy();
    BC_DYNA_AMNT.ResetAndDestroy();
    BC_DYNA_AMNT_DIFF.ResetAndDestroy();
    BC_DYNA_PRICE_INS.ResetAndDestroy();
    BC_DYNA_PRICE_MMP.ResetAndDestroy();
    BC_DYNA_PRICE_GAP.ResetAndDestroy();
    BC_DYNA_TRADENUM.ResetAndDestroy();
    BC_MIN_NUMBER.ResetAndDestroy();
    BC_MIN_TIME.ResetAndDestroy();
    BC_MINDAY_PRICE.ResetAndDestroy();
    BC_MINDAY_PRICE_DIFFS.ResetAndDestroy();
    BC_MINDAY_PRICE_DIFF.ResetAndDestroy();
    BC_MIN_VOL.ResetAndDestroy();
    BC_MINDAY_STRONG.ResetAndDestroy();
    BC_MINDAY_STRONG_DIFF.ResetAndDestroy();
    BC_DAY_NUMBER.ResetAndDestroy();
    BC_DAY_TIME.ResetAndDestroy();
    BC_DAY_TIME_MIND.ResetAndDestroy();
    BC_DAY_TIME_MINM.ResetAndDestroy();
    BC_DAY_VOL.ResetAndDestroy();
    BC_DAY_IND.ResetAndDestroy();
    BC_DAY_IND_DIFF.ResetAndDestroy();
    BC_EXP_MACD.ResetAndDestroy();
    BC_EXP_KDJ.ResetAndDestroy();
    BC_EXP_KDJ_DIFF.ResetAndDestroy();
    BC_EXP_VR.ResetAndDestroy();
    BC_EXP_VR_DIFF.ResetAndDestroy();
    BC_GRID_LB.ResetAndDestroy();
    BC_GRID_HSL.ResetAndDestroy();
    BC_GRID_ZF.ResetAndDestroy();
    BC_TRADE_NUMBER.ResetAndDestroy();
    BC_BARGAIN_TIMEDIFF.ResetAndDestroy();
    BC_TRADE_PRICE.ResetAndDestroy();
    BC_TRADE_PRICE_DIFFS.ResetAndDestroy();
    BC_BARGAIN_TRADENUM_DIFF.ResetAndDestroy();
    BC_BARGAIN_VOL.ResetAndDestroy();
    BC_DYNA_ZLZC.ResetAndDestroy();
    BC_AMT.ResetAndDestroy();
    BC_AMT_DIFF.ResetAndDestroy();
    BC_MINDAY_AMNT.ResetAndDestroy();
    BC_MINDAY_AMNT_DIFF.ResetAndDestroy();
    BC_BARGAIN_QH_VOL.ResetAndDestroy();
    BC_BARGAIN_QH_OI.ResetAndDestroy();
    BC_DYNA_QH_VOL_DIFF.ResetAndDestroy();
    BC_DYNA_QH_VOL_DIFFS.ResetAndDestroy();
}

void CBitStreamConst::ConstructL()
{
    BC_DYNA_TIMEDIFF.Append(new TBitCode(0x00, 1, 'C', 0, 3)); // 0				= 3s
    BC_DYNA_TIMEDIFF.Append(new TBitCode(0x06, 3, 'C', 0, 6)); // 110				= 6s
    BC_DYNA_TIMEDIFF.Append(new TBitCode(0x02, 2, 'D', 4, 0)); // 10	+4Bit		= 4Bit
    BC_DYNA_TIMEDIFF.Append(new TBitCode(0x07, 3, 'O', 18, 0)); // 111	+18Bit		= 18Bit Org

    BC_DYNA_PRICE_DIFF.Append(new TBitCode(0x00, 1, 'D', 4, 0)); // 0	+4Bit		= 4Bit
    BC_DYNA_PRICE_DIFF.Append(new TBitCode(0x02, 2, 'D', 6, 16)); // 10	+6Bit		= 6Bit+16
    BC_DYNA_PRICE_DIFF.Append(new TBitCode(0x06, 3, 'D', 8, 80)); // 110	+8Bit		= 8Bit+64+16
    BC_DYNA_PRICE_DIFF.Append(new TBitCode(0x0E, 4, 'D', 16, 336)); // 1110+16Bit		= 16Bit+256+64+16
    BC_DYNA_PRICE_DIFF.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111+32Bit		= 32Bit Org

    BC_DYNA_PRICE_DIFFS.Append(new TBitCode(0x00, 1, 'I', 4, 0)); // 0	+4Bit		= 4Bit
    BC_DYNA_PRICE_DIFFS.Append(new TBitCode(0x02, 2, 'I', 6, 8)); // 10	+6Bit		= 6Bit+8
    BC_DYNA_PRICE_DIFFS.Append(new TBitCode(0x06, 3, 'I', 8, 40)); // 110	+8Bit		= 8Bit+32+8
    BC_DYNA_PRICE_DIFFS.Append(new TBitCode(0x0E, 4, 'I', 16, 168)); // 1110	+16Bit		= 16Bit+128+32+8
    BC_DYNA_PRICE_DIFFS.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111 +32Bit		= 32Bit Org

    BC_DYNA_VOL.Append(new TBitCode(0x06, 3, 'D', 12, 0)); // 110	+12Bit		= 12Bit
    BC_DYNA_VOL.Append(new TBitCode(0x02, 2, 'D', 16, 4096)); // 10	+16Bit		= 16Bit+4096
    BC_DYNA_VOL.Append(new TBitCode(0x00, 1, 'D', 24, 69632)); // 0	+24Bit		= 24Bit+65536+4096
    BC_DYNA_VOL.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111  +32Bit		= 32Bit Org

    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x02, 2, 'H', 4, 0)); // 10	+4Bit		= (4Bit)*100
    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x00, 1, 'H', 8, 16)); // 0	+8Bit		= (8Bit+16)*100
    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x06, 3, 'H', 12, 272)); // 110	+12Bit		= (12Bit+256+16)*100
    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x1C, 5, 'D', 12, 0)); // 11100+12Bit		= 12Bit
    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x1D, 5, 'D', 16, 4096)); // 11101+16Bit		= 16Bit+4096
    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x1E, 5, 'D', 24, 69632)); // 11110+24Bit		= 24Bit+65536+4096
    BC_DYNA_VOL_DIFF.Append(new TBitCode(0x1F, 5, 'O', 32, 0)); // 11111+32Bit		= 32Bit Org

    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x00, 1, 'h', 6, 0)); // 0	+6Bit		= (6Bit)*100
    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x02, 2, 'h', 8, 32)); // 10	+8Bit		= (8Bit+32)*100
    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x06, 3, 'h', 12, 160)); // 110	+12Bit		= (12Bit+128+32)*100
    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x1C, 5, 'I', 12, 0)); // 11100+12Bit		= 12Bit
    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x1D, 5, 'I', 16, 2048)); // 11101+16Bit		= 16Bit+2048
    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x1E, 5, 'I', 24, 34816)); // 11110+24Bit		= 24Bit+32768+2048
    BC_DYNA_VOL_DIFFS.Append(new TBitCode(0x1F, 5, 'O', 32, 0)); // 11111+32Bit		= 32Bit Org

    BC_DYNA_AMNT.Append(new TBitCode(0x00, 2, 'I', 16, 0)); // 00	+16Bit		= 16Bit
    BC_DYNA_AMNT.Append(new TBitCode(0x01, 2, 'I', 24, 32768)); // 01	+24Bit		= 24Bit+32768
    BC_DYNA_AMNT.Append(new TBitCode(0x02, 2, 'I', 28, 8421376)); // 10	+28Bit		= 28Bit+8388608+32768
    BC_DYNA_AMNT.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org

    BC_DYNA_AMNT_DIFF.Append(new TBitCode(0x00, 2, 'I', 4, 0)); // 00	+4Bit		= 4Bit
    BC_DYNA_AMNT_DIFF.Append(new TBitCode(0x01, 2, 'I', 8, 8)); // 01	+8Bit		= 8Bit+8
    BC_DYNA_AMNT_DIFF.Append(new TBitCode(0x04, 3, 'I', 12, 136)); // 100	+12Bit		= 12Bit+128+8
    BC_DYNA_AMNT_DIFF.Append(new TBitCode(0x05, 3, 'I', 16, 2184)); // 101	+16Bit		= 16Bit+2048+128+8
    BC_DYNA_AMNT_DIFF.Append(new TBitCode(0x06, 3, 'I', 24, 34952)); // 110	+24Bit		= 24Bit+32768+2048+128+8
    BC_DYNA_AMNT_DIFF.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111	+32Bit		= 32Bit Org

    BC_DYNA_PRICE_INS.Append(new TBitCode(0x0E, 4, 'C', 0, 999999)); // 1110				= 0
    BC_DYNA_PRICE_INS.Append(new TBitCode(0x00, 1, 'C', 0, 1)); // 0				= 1
    BC_DYNA_PRICE_INS.Append(new TBitCode(0x02, 2, 'D', 4, 2)); // 10	+4Bit		= 4Bit+2
    BC_DYNA_PRICE_INS.Append(new TBitCode(0x06, 3, 'D', 16, 18)); // 110  +16Bit		= 16Bit+16+2
    BC_DYNA_PRICE_INS.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111 +32Bit		= 32Bit Org

    BC_DYNA_PRICE_MMP.Append(new TBitCode(0x00, 2, 'C', 0, 999999)); // 00				= Psell1 = Pnew
    BC_DYNA_PRICE_MMP.Append(new TBitCode(0x01, 2, 'C', 0, 0)); // 01				= Pbuy1 = Pnew
    BC_DYNA_PRICE_MMP.Append(new TBitCode(0x02, 2, 'I', 4, 0)); // 10	+4Bit		= 4Bit
    BC_DYNA_PRICE_MMP.Append(new TBitCode(0x06, 3, 'I', 8, 8)); // 110  +8Bit		= 8Bit+8
    BC_DYNA_PRICE_MMP.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111	+32Bit		= 32Bit Org

    BC_DYNA_PRICE_GAP.Append(new TBitCode(0x00, 1, 'C', 0, 2)); // 0				= 2
    BC_DYNA_PRICE_GAP.Append(new TBitCode(0x02, 2, 'D', 3, 3)); // 10	+3Bit		= 3Bit+3
    BC_DYNA_PRICE_GAP.Append(new TBitCode(0x06, 3, 'D', 8, 11)); // 110  +8Bit		= 8Bit+8+3
    BC_DYNA_PRICE_GAP.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111	+32Bit		= 32Bit Org

    BC_DYNA_TRADENUM.Append(new TBitCode(0x02, 2, 'D', 8, 0)); // 10	+8Bit		= 8Bit
    BC_DYNA_TRADENUM.Append(new TBitCode(0x00, 1, 'D', 12, 256)); // 0	+12Bit		= 12Bit+256
    BC_DYNA_TRADENUM.Append(new TBitCode(0x06, 3, 'D', 16, 4352)); // 110	+16Bit		= 16Bit+4096+256
    BC_DYNA_TRADENUM.Append(new TBitCode(0x0E, 4, 'D', 24, 69888)); // 1110	+24Bit		= 24Bit+65536+4096+256
    BC_DYNA_TRADENUM.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111	+32Bit		= 32Bit Org

    BC_MIN_NUMBER.Append(new TBitCode(0x00, 1, 'C', 0, 0)); //0				= 0
    BC_MIN_NUMBER.Append(new TBitCode(0x02, 2, 'D', 4, 1)); //10	+4Bit	= 4Bit+1
    BC_MIN_NUMBER.Append(new TBitCode(0x06, 3, 'D', 8, 17)); //110	+8Bit	= 8Bit+16+1
    BC_MIN_NUMBER.Append(new TBitCode(0x07, 3, 'O', 16, 0)); //111	+16Bit	= 16Bit

    BC_MIN_TIME.Append(new TBitCode(0x00, 1, 'C', 0, 1)); //0				= 1\x{02b1}\xBC\x{4d65}\x{03bb}
    BC_MIN_TIME.Append(new TBitCode(0x02, 2, 'D', 5, 2)); //10	+5Bit	= 5Bit+2\x{02b1}\xBC\x{4d65}\x{03bb}
    BC_MIN_TIME.Append(new TBitCode(0x06, 3, 'D', 8, 34)); //110	+8Bit	= 8Bit+32+2\x{02b1}\xBC\x{4d65}\x{03bb}
    BC_MIN_TIME.Append(new TBitCode(0x07, 3, 'O', 16, 0)); //111	+16Bit	= 16Bit\x{02b1}\xBC\x{4d65}\x{03bb}

    BC_MINDAY_PRICE.Append(new TBitCode(0x02, 2, 'D', 8, 0)); //10	+8Bit		= 8Bit
    BC_MINDAY_PRICE.Append(new TBitCode(0x00, 1, 'D', 16, 256)); //0		+16Bit		= 16Bit+256
    BC_MINDAY_PRICE.Append(new TBitCode(0x06, 3, 'D', 24, 65792)); //110	+24Bit		= 24Bit+65536+256
    BC_MINDAY_PRICE.Append(new TBitCode(0x07, 3, 'O', 32, 0)); //111	+32Bit		= 32Bit Org

    BC_MINDAY_PRICE_DIFFS.Append(new TBitCode(0x00, 1, 'I', 4, 0)); // 0	+4Bit		= 4Bit
    BC_MINDAY_PRICE_DIFFS.Append(new TBitCode(0x02, 2, 'I', 6, 8)); // 10	+6Bit		= 6Bit+8
    BC_MINDAY_PRICE_DIFFS.Append(new TBitCode(0x06, 3, 'I', 8, 40)); // 110	+8Bit		= 8Bit+32+8
    BC_MINDAY_PRICE_DIFFS.Append(new TBitCode(0x0E, 4, 'I', 16, 168)); // 1110	+16Bit		= 16Bit+128+32+8
    BC_MINDAY_PRICE_DIFFS.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111 +32Bit		= 32Bit Org

    BC_MINDAY_PRICE_DIFF.Append(new TBitCode(0x00, 1, 'D', 4, 0)); // 0	+4Bit		= 4Bit
    BC_MINDAY_PRICE_DIFF.Append(new TBitCode(0x02, 2, 'D', 6, 16)); // 10	+6Bit		= 6Bit+16
    BC_MINDAY_PRICE_DIFF.Append(new TBitCode(0x06, 3, 'D', 8, 80)); // 110	+8Bit		= 8Bit+64+16
    BC_MINDAY_PRICE_DIFF.Append(new TBitCode(0x0E, 4, 'D', 16, 336)); // 1110+16Bit		= 16Bit+256+64+16
    BC_MINDAY_PRICE_DIFF.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111+32Bit		= 32Bit Org

    BC_MIN_VOL.Append(new TBitCode(0x00, 1, 'D', 12, 0)); // 0	+12Bit		= 12Bit
    BC_MIN_VOL.Append(new TBitCode(0x02, 2, 'D', 16, 4096)); // 10	+16Bit		= 16Bit+4096
    BC_MIN_VOL.Append(new TBitCode(0x06, 3, 'D', 24, 69632)); // 110	+24Bit		= 24Bit+65536+4096
    BC_MIN_VOL.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111  +32Bit		= 32Bit Org

    BC_MINDAY_STRONG.Append(new TBitCode(0x00, 2, 'I', 8, 0)); // 00	+8Bit		= 8Bit
    BC_MINDAY_STRONG.Append(new TBitCode(0x01, 2, 'I', 11, 128)); // 01	+11Bit		= 11Bit+128
    BC_MINDAY_STRONG.Append(new TBitCode(0x02, 2, 'I', 13, 1152)); // 10	+13Bit		= 13Bit+1024+128
    BC_MINDAY_STRONG.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org

    BC_MINDAY_STRONG_DIFF.Append(new TBitCode(0x00, 1, 'I', 3, 0)); // 0	+3Bit		= 3Bit
    BC_MINDAY_STRONG_DIFF.Append(new TBitCode(0x02, 2, 'I', 6, 4)); // 10	+6Bit		= 6Bit+4
    BC_MINDAY_STRONG_DIFF.Append(new TBitCode(0x06, 3, 'I', 10, 36)); // 110	+10Bit		= 10Bit+32+4
    BC_MINDAY_STRONG_DIFF.Append(new TBitCode(0x0E, 4, 'I', 14, 548)); // 1110	+14Bit		= 14Bit+512+32+4
    BC_MINDAY_STRONG_DIFF.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111	+32Bit		= 32Bit Org

    BC_DAY_NUMBER.Append(new TBitCode(0x00, 1, 'C', 0, 1)); //0				= 1
    BC_DAY_NUMBER.Append(new TBitCode(0x02, 2, 'D', 7, 2)); //10	+7Bit	= 7Bit+2
    BC_DAY_NUMBER.Append(new TBitCode(0x06, 3, 'D', 12, 130)); //110	+12Bit	= 12Bit+128+2
    BC_DAY_NUMBER.Append(new TBitCode(0x0E, 4, 'D', 16, 4226)); //1110	+16Bit	= 16Bit+4096+128+2
    BC_DAY_NUMBER.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); //1111	+32Bit	= 32Bit Org

    BC_DAY_TIME.Append(new TBitCode(0x00, 1, 'C', 0, 1)); //0				= 1\xCC\xEC
    BC_DAY_TIME.Append(new TBitCode(0x02, 2, 'C', 0, 3)); //10			= 3\xCC\xEC
    BC_DAY_TIME.Append(new TBitCode(0x0C, 4, 'C', 0, 2)); //1100			= 2\xCC\xEC
    BC_DAY_TIME.Append(new TBitCode(0x0D, 4, 'D', 4, 4)); //1101	+4Bit	= 4Bit+4\xCC\xEC
    BC_DAY_TIME.Append(new TBitCode(0x0E, 4, 'D', 8, 20)); //1110	+8Bit	= 8Bit+20\xCC\xEC
    BC_DAY_TIME.Append(new TBitCode(0x0F, 4, 'O', 16, 0)); //1111	+16Bit	= 16Bit\xCC\xEC

    BC_DAY_TIME_MIND.Append(new TBitCode(0x00, 1, 'C', 0, 0)); //0				= 0\xCC\xEC
    BC_DAY_TIME_MIND.Append(new TBitCode(0x02, 2, 'C', 0, 1)); //10			= 1\xCC\xEC
    BC_DAY_TIME_MIND.Append(new TBitCode(0x06, 3, 'C', 0, 3)); //110			= 3\xCC\xEC
    BC_DAY_TIME_MIND.Append(new TBitCode(0x1C, 5, 'D', 4, 0)); //11100	+4Bit	= 4Bit\xCC\xEC
    BC_DAY_TIME_MIND.Append(new TBitCode(0x1D, 5, 'D', 8, 16)); //11101	+8Bit	= 8Bit+16\xCC\xEC
    BC_DAY_TIME_MIND.Append(new TBitCode(0x1E, 5, 'O', 16, 0)); //11110	+16Bit	= 16Bit\xCC\xEC

    BC_DAY_TIME_MINM.Append(new TBitCode(0x00, 1, 'D', 5, 0)); //0		+5Bit	= 5Bit\x{02b1}\xBC\x{4d65}\x{03bb}
    BC_DAY_TIME_MINM.Append(new TBitCode(0x02, 2, 'D', 8, 32)); //10	+8Bit	= 8Bit+32\x{02b1}\xBC\x{4d65}\x{03bb}
    BC_DAY_TIME_MINM.Append(new TBitCode(0x03, 2, 'O', 12, 0)); //11	+12Bit	= 12Bit\x{02b1}\xBC\x{4d65}\x{03bb}

    BC_DAY_VOL.Append(new TBitCode(0x0F, 4, 'C', 0, 0)); // 1111				= 0
    BC_DAY_VOL.Append(new TBitCode(0x0E, 4, 'D', 12, 0)); // 1110	+12Bit		= 12Bit
    BC_DAY_VOL.Append(new TBitCode(0x02, 2, 'D', 16, 4096)); // 10	+16Bit		= 16Bit+4096
    BC_DAY_VOL.Append(new TBitCode(0x00, 1, 'D', 24, 69632)); // 0	+24Bit		= 24Bit+65536+4096
    BC_DAY_VOL.Append(new TBitCode(0x06, 3, 'O', 32, 0)); // 110  +32Bit		= 32Bit Org

    BC_DAY_IND.Append(new TBitCode(0x00, 2, 'I', 8, 0)); // 00	+8Bit		= 8Bit
    BC_DAY_IND.Append(new TBitCode(0x01, 2, 'I', 11, 128)); // 01	+11Bit		= 11Bit+128
    BC_DAY_IND.Append(new TBitCode(0x02, 2, 'I', 14, 1152)); // 10	+14Bit		= 14Bit+1024+128
    BC_DAY_IND.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org

    BC_DAY_IND_DIFF.Append(new TBitCode(0x00, 1, 'I', 3, 0)); // 0	+3Bit		= 3Bit
    BC_DAY_IND_DIFF.Append(new TBitCode(0x02, 2, 'I', 6, 4)); // 10	+6Bit		= 6Bit+4
    BC_DAY_IND_DIFF.Append(new TBitCode(0x06, 3, 'I', 10, 36)); // 110	+10Bit		= 10Bit+32+4
    BC_DAY_IND_DIFF.Append(new TBitCode(0x0E, 4, 'I', 14, 548)); // 1110	+14Bit		= 14Bit+512+32+4
    BC_DAY_IND_DIFF.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111	+32Bit		= 32Bit Org


    // MACD - DIF, DEA
    BC_EXP_MACD.Append(new TBitCode(0x00, 2, 'I', 12, 0)); // 00	+12Bit		= 12Bit
    BC_EXP_MACD.Append(new TBitCode(0x01, 2, 'I', 16, 2048)); // 01	+16Bit		= 16Bit+2048
    BC_EXP_MACD.Append(new TBitCode(0x02, 2, 'I', 20, 34816)); // 10	+20Bit		= 20Bit+32768+2048
    BC_EXP_MACD.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org


    // KDJ - K, D; RSI; WR
    BC_EXP_KDJ.Append(new TBitCode(0x00, 1, 'D', 17, 0)); // 0	+17Bit		= 17Bit
    BC_EXP_KDJ.Append(new TBitCode(0x01, 1, 'O', 32, 0)); // 1	+32Bit		= 32Bit Org

    BC_EXP_KDJ_DIFF.Append(new TBitCode(0x00, 1, 'I', 13, 0)); // 0	+13Bit		= 13Bit
    BC_EXP_KDJ_DIFF.Append(new TBitCode(0x02, 2, 'I', 16, 4096)); // 10	+16Bit		= 16Bit+4096
    BC_EXP_KDJ_DIFF.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org


    // VR
    BC_EXP_VR.Append(new TBitCode(0x00, 1, 'D', 20, 0)); // 0	+20Bit		= 20Bit
    BC_EXP_VR.Append(new TBitCode(0x01, 1, 'O', 32, 0)); // 1	+32Bit		= 32Bit Org

    BC_EXP_VR_DIFF.Append(new TBitCode(0x00, 1, 'I', 14, 0)); // 0	+14Bit		= 14Bit
    BC_EXP_VR_DIFF.Append(new TBitCode(0x02, 2, 'I', 17, 8192)); // 10	+17Bit		= 17Bit+8192
    BC_EXP_VR_DIFF.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org


    // \xC1\xBF\xB1\xC8
    BC_GRID_LB.Append(new TBitCode(0x00, 1, 'D', 8, 0)); // 0	+8Bit	  	= 8Bit
    BC_GRID_LB.Append(new TBitCode(0x02, 2, 'D', 11, 256)); // 10	+11Bit	  = 11Bit+256
    BC_GRID_LB.Append(new TBitCode(0x06, 3, 'D', 14, 2304)); // 110+14Bit    = 14Bit+2048+256
    BC_GRID_LB.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111+32Bit		= 32Bit Org


    // \xBB\xBB\xCA\xD6\xC2\xCA
    BC_GRID_HSL.Append(new TBitCode(0x00, 1, 'D', 8, 0)); // 0	+8Bit	    = 8Bit
    BC_GRID_HSL.Append(new TBitCode(0x02, 2, 'D', 12, 256)); // 10 +12Bit    = 12Bit+256
    BC_GRID_HSL.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11 +32Bit		= 32Bit Org

    // \xD5\xF0\xB7\xF9
    BC_GRID_ZF.Append(new TBitCode(0x00, 1, 'D', 9, 0)); // 0	+9Bit	    = 9Bit
    BC_GRID_ZF.Append(new TBitCode(0x02, 2, 'D', 11, 512)); // 10 +11Bit    = 11Bit+512
    BC_GRID_ZF.Append(new TBitCode(0x06, 3, 'D', 16, 2560)); // 110+16Bit    = 16Bit+2048+512
    BC_GRID_ZF.Append(new TBitCode(0x07, 3, 'O', 32, 0)); // 111+32Bit		= 32Bit Org

    BC_TRADE_NUMBER.Append(new TBitCode(0x00, 1, 'C', 0, 1)); //0				= 1
    BC_TRADE_NUMBER.Append(new TBitCode(0x02, 2, 'D', 7, 2)); //10	+7Bit	= 7Bit+2
    BC_TRADE_NUMBER.Append(new TBitCode(0x06, 3, 'D', 12, 130)); //110	+12Bit	= 12Bit+128+2
    BC_TRADE_NUMBER.Append(new TBitCode(0x0E, 4, 'D', 16, 4226)); //1110	+16Bit	= 16Bit+4096+128+2
    BC_TRADE_NUMBER.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); //1111	+32Bit	= 32Bit Org

    BC_BARGAIN_TIMEDIFF.Append(new TBitCode(0x00, 1, 'C', 0, 3)); // 0				= 3s
    BC_BARGAIN_TIMEDIFF.Append(new TBitCode(0x06, 3, 'C', 0, 6)); // 110				= 6s
    BC_BARGAIN_TIMEDIFF.Append(new TBitCode(0x02, 2, 'D', 4, 0)); // 10	+4Bit		= 4Bit
    BC_BARGAIN_TIMEDIFF.Append(new TBitCode(0x0E, 4, 'D', 8, 16)); // 1110	+8Bit		= 8Bit+16
    BC_BARGAIN_TIMEDIFF.Append(new TBitCode(0x0F, 4, 'O', 18, 0)); // 1111	+18Bit		= 18Bit Org

    BC_TRADE_PRICE.Append(new TBitCode(0x02, 2, 'D', 8, 0)); //10	+8Bit		= 8Bit
    BC_TRADE_PRICE.Append(new TBitCode(0x00, 1, 'D', 16, 256)); //0		+16Bit		= 16Bit+256
    BC_TRADE_PRICE.Append(new TBitCode(0x06, 3, 'D', 24, 65792)); //110	+24Bit		= 24Bit+65536+256
    BC_TRADE_PRICE.Append(new TBitCode(0x07, 3, 'O', 32, 0)); //111	+32Bit		= 32Bit Org

    BC_TRADE_PRICE_DIFFS.Append(new TBitCode(0x00, 1, 'C', 0, 0)); // 0				= 0
    BC_TRADE_PRICE_DIFFS.Append(new TBitCode(0x02, 2, 'I', 2, 0)); // 10	+2Bit		= 2Bit
    BC_TRADE_PRICE_DIFFS.Append(new TBitCode(0x06, 3, 'I', 4, 2)); // 110	+4Bit		= 4Bit+2
    BC_TRADE_PRICE_DIFFS.Append(new TBitCode(0x0E, 4, 'I', 8, 10)); // 1110	+8Bit		= 8Bit+8+2
    BC_TRADE_PRICE_DIFFS.Append(new TBitCode(0x1E, 5, 'I', 16, 138)); // 11110+16Bit		= 16Bit+128+8+2
    BC_TRADE_PRICE_DIFFS.Append(new TBitCode(0x1F, 5, 'O', 32, 0)); // 11111+32Bit		= 32Bit Org

    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x1E, 5, 'C', 0, 0)); // 11110			= 0
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x00, 2, 'C', 0, 1)); // 00				= 1
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x01, 2, 'C', 0, 2)); // 01				= 2
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x02, 2, 'D', 4, 3)); // 10	+4Bit		= 4Bit+3
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x06, 3, 'D', 6, 19)); // 110	+6Bit		= 6Bit+16+3
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x0E, 4, 'D', 8, 83)); // 1110	+8Bit		= 8Bit+64+16+3
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x3E, 6, 'D', 14, 339)); // 111110+8Bit		= 14Bit+256+64+16+3
    BC_BARGAIN_TRADENUM_DIFF.Append(new TBitCode(0x3F, 6, 'O', 32, 0)); // 111111+32Bit		= 32Bit Org

    BC_BARGAIN_VOL.Append(new TBitCode(0x00, 1, 'H', 4, 0)); // 0	+4Bit		= (4Bit)*100
    BC_BARGAIN_VOL.Append(new TBitCode(0x02, 2, 'H', 8, 16)); // 10	+8Bit		= (8Bit+16)*100
    BC_BARGAIN_VOL.Append(new TBitCode(0x0C, 4, 'H', 12, 272)); // 1100	+12Bit		= (12Bit+256+16)*100
    BC_BARGAIN_VOL.Append(new TBitCode(0x0D, 4, 'D', 12, 0)); // 1101+12Bit		= 12Bit
    BC_BARGAIN_VOL.Append(new TBitCode(0x0E, 4, 'D', 16, 4096)); // 1110+16Bit		= 16Bit+4096
    BC_BARGAIN_VOL.Append(new TBitCode(0x1E, 5, 'D', 24, 69632)); // 11110+24Bit		= 24Bit+65536+4096
    BC_BARGAIN_VOL.Append(new TBitCode(0x1F, 5, 'O', 32, 0)); // 11111+32Bit		= 32Bit Org

    BC_DYNA_ZLZC.Append(new TBitCode(0x00, 1, 'D', 5, 0)); // 0	+5Bit		= 5Bit
    BC_DYNA_ZLZC.Append(new TBitCode(0x01, 1, 'O', 8, 0)); // 1    +8Bit		= 8Bit Org

    BC_AMT.Append(new TBitCode(0x00, 2, 'I', 8, 0)); // 00	+8Bit		= 8Bit
    BC_AMT.Append(new TBitCode(0x01, 2, 'I', 11, 128)); // 01	+11Bit		= 11Bit+128
    BC_AMT.Append(new TBitCode(0x02, 2, 'I', 13, 1152)); // 10	+13Bit		= 13Bit+1024+128
    BC_AMT.Append(new TBitCode(0x03, 2, 'O', 32, 0)); // 11	+32Bit		= 32Bit Org

    BC_AMT_DIFF.Append(new TBitCode(0x00, 1, 'I', 3, 0)); // 0	+3Bit		= 3Bit
    BC_AMT_DIFF.Append(new TBitCode(0x02, 2, 'I', 6, 4)); // 10	+6Bit		= 6Bit+4
    BC_AMT_DIFF.Append(new TBitCode(0x06, 3, 'I', 10, 36)); // 110	+10Bit		= 10Bit+32+4
    BC_AMT_DIFF.Append(new TBitCode(0x0E, 4, 'I', 14, 548)); // 1110	+14Bit		= 14Bit+512+32+4
    BC_AMT_DIFF.Append(new TBitCode(0x0F, 4, 'O', 32, 0)); // 1111	+32Bit		= 32Bit Org

    BC_MINDAY_AMNT.Append(new TBitCode(0x00, 2, 'I', 16, 0));// 00	+16Bit		= 16Bit
    BC_MINDAY_AMNT.Append(new TBitCode(0x01, 2, 'I', 24, 32768));// 01	+24Bit		= 24Bit+32768
    BC_MINDAY_AMNT.Append(new TBitCode(0x02, 2, 'I', 28, 8421376));// 10	+28Bit		= 28Bit+8388608+32768
    BC_MINDAY_AMNT.Append(new TBitCode(0x03, 2, 'O', 32, 0));// 11	+32Bit		= 32Bit Org

    BC_MINDAY_AMNT_DIFF.Append(new TBitCode(0x00, 2, 'I', 4, 0));// 00	+4Bit		= 4Bit
    BC_MINDAY_AMNT_DIFF.Append(new TBitCode(0x01, 2, 'I', 8, 8));// 01	+8Bit		= 8Bit+8
    BC_MINDAY_AMNT_DIFF.Append(new TBitCode(0x04, 3, 'I', 12, 136));// 100	+12Bit		= 12Bit+128+8
    BC_MINDAY_AMNT_DIFF.Append(new TBitCode(0x05, 3, 'I', 16, 2184));// 101	+16Bit		= 16Bit+2048+128+8
    BC_MINDAY_AMNT_DIFF.Append(new TBitCode(0x06, 3, 'I', 24, 34952));// 110	+24Bit		= 24Bit+32768+2048+128+8
    BC_MINDAY_AMNT_DIFF.Append(new TBitCode(0x07, 3, 'O', 32, 0));// 111	+32Bit		= 32Bit Org

    BC_BARGAIN_QH_VOL.Append(new TBitCode(0x00, 1, 'D', 12, 0));// 0 +12Bit = 12Bit
    BC_BARGAIN_QH_VOL.Append(new TBitCode(0x02, 2, 'D', 16, 4096));// 10 +16Bit = 16Bit+4096
    BC_BARGAIN_QH_VOL.Append(new TBitCode(0x06, 3, 'D', 24, 69632));// 110 +24Bit = 24Bit+65536+4096
    BC_BARGAIN_QH_VOL.Append(new TBitCode(0x07, 3, 'O', 32, 0));// 111 +32Bit = 32Bit Org

    BC_BARGAIN_QH_OI.Append(new TBitCode(0x00, 1, 'I', 12, 0));// 0 +12Bit = 12Bit
    BC_BARGAIN_QH_OI.Append(new TBitCode(0x02, 2, 'I', 16, 2048));// 10 +16Bit = 16Bit+2048
    BC_BARGAIN_QH_OI.Append(new TBitCode(0x06, 3, 'I', 24, 34816));// 110 +24Bit = 24Bit+32768+2048
    BC_BARGAIN_QH_OI.Append(new TBitCode(0x07, 3, 'O', 32, 0));// 111 +32Bit = 32Bit Org


    BC_DYNA_QH_VOL_DIFF.Append(new TBitCode(0x06, 3, 'D', 12, 0));// 110 +12Bit = 12Bit
    BC_DYNA_QH_VOL_DIFF.Append(new TBitCode(0x02, 2, 'D', 16, 4096));// 10 +16Bit = 16Bit+4096
    BC_DYNA_QH_VOL_DIFF.Append(new TBitCode(0x00, 1, 'D', 24, 69632));// 0 +24Bit = 24Bit+65536+4096
    BC_DYNA_QH_VOL_DIFF.Append(new TBitCode(0x07, 3, 'O', 32, 0));// 111 +32Bit = 32Bit Org

    BC_DYNA_QH_VOL_DIFFS.Append(new TBitCode(0x00, 1, 'I', 12, 0));// 0 +12Bit = 12Bit
    BC_DYNA_QH_VOL_DIFFS.Append(new TBitCode(0x02, 2, 'I', 16, 2048));// 10 +16Bit = 16Bit+2048
    BC_DYNA_QH_VOL_DIFFS.Append(new TBitCode(0x06, 3, 'I', 24, 34816));// 110 +24Bit = 24Bit+32768+2048
    BC_DYNA_QH_VOL_DIFFS.Append(new TBitCode(0x07, 3, 'O', 32, 0));// 111 +32Bit = 32Bit Org
}



TBitStream::TBitStream(TPtrC8& pcBuf):
    m_pcBuf(NULL, 0), 
    BC_DYNA_TIMEDIFF(BITSTREAMCONST->BC_DYNA_TIMEDIFF), 
    BC_DYNA_PRICE_DIFF(BITSTREAMCONST->BC_DYNA_PRICE_DIFF), 
    BC_DYNA_PRICE_DIFFS(BITSTREAMCONST->BC_DYNA_PRICE_DIFFS), 
    BC_DYNA_VOL(BITSTREAMCONST->BC_DYNA_VOL),
    BC_DYNA_VOL_DIFF(BITSTREAMCONST->BC_DYNA_VOL_DIFF), 
    BC_DYNA_VOL_DIFFS(BITSTREAMCONST->BC_DYNA_VOL_DIFFS), 
    BC_DYNA_AMNT(BITSTREAMCONST->BC_DYNA_AMNT),
    BC_DYNA_AMNT_DIFF(BITSTREAMCONST->BC_DYNA_AMNT_DIFF), 
    BC_DYNA_PRICE_INS(BITSTREAMCONST->BC_DYNA_PRICE_INS),
    BC_DYNA_PRICE_MMP(BITSTREAMCONST->BC_DYNA_PRICE_MMP), 
    BC_DYNA_PRICE_GAP(BITSTREAMCONST->BC_DYNA_PRICE_GAP), 
    BC_DYNA_TRADENUM(BITSTREAMCONST->BC_DYNA_TRADENUM),
    BC_MIN_NUMBER(BITSTREAMCONST->BC_MIN_NUMBER), 
    BC_MIN_TIME(BITSTREAMCONST->BC_MIN_TIME),
    BC_MINDAY_PRICE(BITSTREAMCONST->BC_MINDAY_PRICE), 
    BC_MINDAY_PRICE_DIFFS(BITSTREAMCONST->BC_MINDAY_PRICE_DIFFS), 
    BC_MINDAY_PRICE_DIFF(BITSTREAMCONST->BC_MINDAY_PRICE_DIFF), 
    BC_MIN_VOL(BITSTREAMCONST->BC_MIN_VOL),
    BC_MINDAY_STRONG(BITSTREAMCONST->BC_MINDAY_STRONG), 
    BC_MINDAY_STRONG_DIFF(BITSTREAMCONST->BC_MINDAY_STRONG_DIFF), 
    BC_DAY_NUMBER(BITSTREAMCONST->BC_DAY_NUMBER),
    BC_DAY_TIME(BITSTREAMCONST->BC_DAY_TIME),
    BC_DAY_TIME_MIND(BITSTREAMCONST->BC_DAY_TIME_MIND), 
    BC_DAY_TIME_MINM(BITSTREAMCONST->BC_DAY_TIME_MINM), 
    BC_DAY_VOL(BITSTREAMCONST->BC_DAY_VOL), 
    BC_DAY_IND(BITSTREAMCONST->BC_DAY_IND), 
    BC_DAY_IND_DIFF(BITSTREAMCONST->BC_DAY_IND_DIFF),
    BC_EXP_MACD(BITSTREAMCONST->BC_EXP_MACD), 
    BC_EXP_KDJ(BITSTREAMCONST->BC_EXP_KDJ),
    BC_EXP_KDJ_DIFF(BITSTREAMCONST->BC_EXP_KDJ_DIFF), 
    BC_EXP_VR(BITSTREAMCONST->BC_EXP_VR),
    BC_EXP_VR_DIFF(BITSTREAMCONST->BC_EXP_VR_DIFF), 
    BC_GRID_LB(BITSTREAMCONST->BC_GRID_LB),
    BC_GRID_HSL(BITSTREAMCONST->BC_GRID_HSL), 
    BC_GRID_ZF(BITSTREAMCONST->BC_GRID_ZF),
    BC_TRADE_NUMBER(BITSTREAMCONST->BC_TRADE_NUMBER), 
    BC_BARGAIN_TIMEDIFF(BITSTREAMCONST->BC_BARGAIN_TIMEDIFF), 
    BC_TRADE_PRICE(BITSTREAMCONST->BC_TRADE_PRICE),
    BC_TRADE_PRICE_DIFFS(BITSTREAMCONST->BC_TRADE_PRICE_DIFFS), 
    BC_BARGAIN_TRADENUM_DIFF(BITSTREAMCONST->BC_BARGAIN_TRADENUM_DIFF), 
    BC_BARGAIN_VOL(BITSTREAMCONST->BC_BARGAIN_VOL), 
    BC_DYNA_ZLZC(BITSTREAMCONST->BC_DYNA_ZLZC), 
    BC_AMT(BITSTREAMCONST->BC_AMT), 
    BC_AMT_DIFF(BITSTREAMCONST->BC_AMT_DIFF), 
    BC_MINDAY_AMNT(BITSTREAMCONST->BC_MINDAY_AMNT), 
    BC_MINDAY_AMNT_DIFF(BITSTREAMCONST->BC_MINDAY_AMNT_DIFF), 
    BC_BARGAIN_QH_VOL(BITSTREAMCONST->BC_BARGAIN_QH_VOL), 
    BC_BARGAIN_QH_OI(BITSTREAMCONST->BC_BARGAIN_QH_OI),
    BC_DYNA_QH_VOL_DIFF(BITSTREAMCONST->BC_DYNA_QH_VOL_DIFF), 
    BC_DYNA_QH_VOL_DIFFS(BITSTREAMCONST->BC_DYNA_QH_VOL_DIFFS)
{
    m_pcBuf.Set(pcBuf);
    m_nBitLen = pcBuf.Length() * 8;
    m_nCurPos = 0;
}

TBitStream::~TBitStream()
{
}

//void CBitStream::SetBuffer(TPtr8& pcBuf)
//{
//	if (m_cBufType==2 && m_pBuffer!=NULL)
//		delete m_pBuffer;
//
//	m_pcBuf.Set(pcBuf);
//	m_nBitLen = pcBuf.Length()*8;
//
//	m_pBuffer = NULL;
//	m_uStartPos = 0;
//
//	m_nCurPos = 0;
//	m_cBufType = 1;
//
//}

//TInt CBitStream::ReallocBuf(const TUint& nBits)
//{
//	if(m_cBufType!=2)
//		return 0;
//
//	TInt nBufBytes = m_nBitLen/8;
//	TInt nDataBytes = (nBits+7)/8;
//
//	if(nBufBytes >= nDataBytes)
//		return 0;
//
//	const TInt nAddBytes = 1024;
//
//	while(nBufBytes < nDataBytes)
//		nBufBytes += nAddBytes;
//
//	HBufC8* pcNewBuf = HBufC8::NewL(nBufBytes);
//	
//	if(m_pBuffer!=NULL)
//	{
//		if(m_nCurPos > 0)
//			pcNewBuf->Des().Copy(m_pcBuf);
//			//CopyMemory(pcNewBuf, m_pcBuf, (m_nCurPos+7)/8);
//		delete m_pBuffer;
//	}
//	m_pBuffer = pcNewBuf;
//	m_pcBuf.Set(m_pBuffer->Des());
//	m_nBitLen = nBufBytes * 8;
//	return nBufBytes;
//}

//TInt CBitStream::WriteDWORD(TInt dw, TInt nBits) 
//{
//	if(nBits <= 0 || nBits > 32)
//		return 0;
//	TInt nRet = nBits;
//
//	dw <<= (32 - nBits);
//	TInt nCurIndex = m_nCurPos / 8;
//	TInt nLastBits = m_nCurPos % 8;
//
//	if(nLastBits != 0)			// fill in the last byte
//	{
//		int nFillBits = 8 - nLastBits;
//
//		m_pcBuf[nCurIndex] &= (TUint8)(0xFF << nFillBits);
//		m_pcBuf[nCurIndex] += (TUint8)(dw >> (32-nFillBits));
//		nCurIndex++;
//
//		if(nFillBits < nBits)
//			dw <<= nFillBits;	// else, finish
//
//		nBits -= nFillBits;
//	}
//	while(nBits > 0)
//	{
//		m_pcBuf[nCurIndex++] = (TUint8)(dw >> 24);
//		dw <<= 8;
//		nBits -= 8;
//	}
//	m_nCurPos += nRet;
//	return nRet;
//}


TInt TBitStream::ReadDWORD(TInt nBits, TBool bMovePos)
{
    if (nBits <= 0 || nBits > 32)
        return 0;

    TInt nCurIndex = m_nCurPos / 8;
    TInt nLastBits = m_nCurPos % 8;

    if (bMovePos)
        m_nCurPos += nBits;

    TInt dw = 0;

    if (nLastBits != 0)
    {
        dw = m_pcBuf[nCurIndex] & (0xFF >> nLastBits);
        nCurIndex++;

        TInt nReadBits = 8 - nLastBits;
        if (nReadBits > nBits)
            dw >>= (nReadBits - nBits);

        nBits -= nReadBits;
    }

    while (nBits > 0)
    {
        if (nBits >= 8)
        {
            dw = (dw << 8) | (m_pcBuf[nCurIndex++] & 0xFF);
            nBits -= 8;
        }
        else
        {
            dw = (dw << nBits) | ((m_pcBuf[nCurIndex] & 0xFF) >> (8 - nBits));
            nBits = 0;
        }
    }
    return dw;
}

TBitCode* TBitStream::MatchCodeEncode(TInt& dw, RPointerArray<TBitCode>& pBitCodes)
{
    TInt nNumOfCodes = pBitCodes.Count();
    if (nNumOfCodes <= 0)
        return NULL;

    TBitCode* pCode = NULL;
    TInt dwSave = 0;

    TInt i = 0;
    for (; i < nNumOfCodes; i++)
    {
        pCode = pBitCodes[i];
        if (pCode->m_cDataType == 'C') // const
        {
            if (dw == pCode->m_dwDataBias)
                break;
        }
        else if (pCode->m_cDataType == 'D') // DWORD
        {
            dwSave = dw - pCode->m_dwDataBias;
            if ((dwSave >> pCode->m_cDataLen) == 0)
            {
                dw = dwSave;
                break;
            }
        }
        else if (pCode->m_cDataType == 'I') // INT
        {
            if ((dw & 0x80000000) != 0)
            {
                dwSave = dw + pCode->m_dwDataBias;
                if ((dwSave >> (pCode->m_cDataLen - 1)) == (0xFFFFFFFF >> (pCode->m_cDataLen - 1)))
                {
                    dw = dwSave;
                    break;
                }
            }
            else
            {
                dwSave = dw - pCode->m_dwDataBias;
                if ((dwSave >> (pCode->m_cDataLen - 1)) == 0)
                {
                    dw = dwSave;
                    break;
                }
            }
        }
        else if (pCode->m_cDataType == 'H') // HUNDRED DWORD
        {
            //TInt  lEncodingData = m_dwEncodingData;
            //if(lEncodingData < 0)
            //	lEncodingData += 0x100000000l;

            if (dw % 100 == 0)
            {
                dwSave = dw / 100 - pCode->m_dwDataBias;
                if ((dwSave >> pCode->m_cDataLen) == 0)
                {
                    dw = dwSave;
                    break;
                }
            }
        }
        else if (pCode->m_cDataType == 'h') // HUNDRED INT
        {
            TInt iValue = dw;
            if (iValue % 100 == 0)
            {
                if (iValue < 0)
                {
                    dwSave = iValue / 100 + pCode->m_dwDataBias;
                    if ((dwSave >> (pCode->m_cDataLen - 1)) == (0xFFFFFFFF >> (pCode->m_cDataLen
                        - 1)))
                    {
                        dw = dwSave;
                        break;
                    }
                }
                else
                {
                    dwSave = iValue / 100 - pCode->m_dwDataBias;
                    if ((dwSave >> (pCode->m_cDataLen - 1)) == 0)
                    {
                        dw = dwSave;
                        break;
                    }
                }
            }
        }
        else if (pCode->m_cDataType == 'O') // ORIGINAL
            break;
    }

    if (i == nNumOfCodes)
        return NULL;

    return pCode;
}

//TInt CBitStream::EncodeData(TInt dwData,RPointerArray<TBitCode>& pBitCodes,
//                          TInt* pdwBase, TBool bReverse)
//    {
//        TInt dw  = dwData;
//        if(pdwBase != NULL)
//        {
//            if(bReverse)
//                dw = *pdwBase - dwData;
//            else
//                dw = dwData - *pdwBase;
//        }
//
//        TBitCode* pCode =  MatchCodeEncode(dw,pBitCodes);
//        if(pCode == NULL)
//           return 0;
//
//        if(pCode->m_cDataType == 'O')
//        {
//            if(pCode->m_cDataLen == 0
//                   || pCode->m_cDataLen != 32 && (dwData >> pCode->m_cDataLen) != 0)
//               return 0;
//
//            WriteDWORD(pCode->m_wCodeBits, pCode->m_cCodeLen);
//            WriteDWORD(dwData, pCode->m_cDataLen);
//        }
//        else
//        {
//            WriteDWORD(pCode->m_wCodeBits, pCode->m_cCodeLen);
//            if(pCode->m_cDataLen > 0)
//                WriteDWORD(dw, pCode->m_cDataLen);
//        }
//
//	return  (pCode->m_cCodeLen + pCode->m_cDataLen);
//  }
//
//
//TInt CBitStream::EncodeXInt32(XInt32 xData, RPointerArray<TBitCode>& pBitCodes,
//		XInt32* pxBase, TBool bReverse)
//	{
//		TInt64 ll = 0;
//		TInt dw  = 0;
//
//		if(pxBase != NULL)
//		{
//			if(bReverse)
//				ll = (TInt64)(*pxBase)-(TInt64)xData;// pxBase->GetValue() - xData.GetValue();
//			else
//				ll = (TInt64)xData - (TInt64)(*pxBase);//xData.GetValue() - pxBase->GetValue();
//		}
//		else
//			ll = (TInt64)xData;//xData.GetValue();
//
//		TBitCode* pCode = NULL;
//	
//		if(ll >= XInt32m_nMinBase && ll <= XInt32m_nMaxBase)
//		{
//			dw = ll.GetTInt();// (TInt)ll;
//			pCode = MatchCodeEncode(dw,pBitCodes);
//		}
//		else
//		{
//			TInt nNumOfCodes = pBitCodes.Count();
//			for(int i = 0; i < nNumOfCodes; i++)
//			{
//				if(pBitCodes[i]->m_cDataType == 'O')
//				{
//					pCode = pBitCodes[i];
//					break;
//				}
//			}
//		}
//		if(pCode == NULL)
//			return 0;
//
//		if(pCode->m_cDataType == 'O')
//		{
//			if(pCode->m_cDataLen != 32)
//				return 0;
//
//			WriteDWORD(pCode->m_wCodeBits, pCode->m_cCodeLen);
//			WriteDWORD(xData.GetRawData(), pCode->m_cDataLen);
//		}
//		else
//		{
//			WriteDWORD(pCode->m_wCodeBits, pCode->m_cCodeLen);
//			if(pCode->m_cDataLen > 0)
//				WriteDWORD(dw, pCode->m_cDataLen);
//		}
//
//		return (pCode->m_cCodeLen + pCode->m_cDataLen);
//}

TBitCode* TBitStream::MatchCodeDecode(TInt& dw, TUint8& cBytes, RPointerArray<TBitCode>& pBitCodes)
{
    dw = 0;
    cBytes = 0;

    if (pBitCodes.Count() == 0)
        return 0;

    TInt nNumOfCodes = pBitCodes.Count();
    if (nNumOfCodes <= 0)
        return 0;

    TInt nReadBits = m_nBitLen - m_nCurPos;

    if (nReadBits <= 0)
        return 0;

    if (nReadBits > 16)
        nReadBits = 16;

    TInt nCode = ReadDWORD(nReadBits, EFalse);

    TBitCode* pCode = NULL;
    TInt i;
    for (i = 0; i < nNumOfCodes; i++)
    {
        pCode = pBitCodes[i];
        if (pCode->m_wCodeBits == (nCode >> (nReadBits - pCode->m_cCodeLen)))
            break;
    }

    if (i == nNumOfCodes)
        return NULL;

    m_nCurPos += pCode->m_cCodeLen;

    TInt dwData = 0;
    if (pCode->m_cDataLen > 0)
        dwData = ReadDWORD(pCode->m_cDataLen, ETrue);

    if (pCode->m_cDataType == 'C') // const
        dw = pCode->m_dwDataBias;
    else if (pCode->m_cDataType == 'D') // DWORD
        dw = dwData + pCode->m_dwDataBias;
    else if (pCode->m_cDataType == 'I') // INT
    {
        if (dwData >> (pCode->m_cDataLen - 1) != 0)
        {
            dwData |= (0xFFFFFFFF << pCode->m_cDataLen);
            dw = dwData - pCode->m_dwDataBias;
        }
        else
            dw = dwData + pCode->m_dwDataBias;
    }
    else if (pCode->m_cDataType == 'H') // HUNDRED
        dw = (dwData + pCode->m_dwDataBias) * 100;
    else if (pCode->m_cDataType == 'h') // HUNDRED INT
    {
        if (dwData >> (pCode->m_cDataLen - 1) != 0)
        {
            dwData |= (0xFFFFFFFF << pCode->m_cDataLen);
            dwData -= pCode->m_dwDataBias;

            dw = dwData * 100;
        }
        else
        {
            dw = (dwData + pCode->m_dwDataBias) * 100;
        }
    }
    else if (pCode->m_cDataType == 'O') // ORIGINAL
        dw = dwData;

    cBytes = pCode->m_cCodeLen + pCode->m_cDataLen;

    return pCode;
}

TUint8 TBitStream::DecodeData(TInt& dwData, RPointerArray<TBitCode>& pBitCodes, TInt* pdwBase,
    TBool bReverse)
{
    dwData = 0;
    TUint8 cBytes = 0;

    TBitCode* pCode = MatchCodeDecode(dwData, cBytes, pBitCodes);
    if (pCode != NULL)
    {
        if (pCode->m_cDataType != 'O' && pdwBase != NULL)
        {
            if (bReverse)
                dwData = *pdwBase - dwData;
            else
                dwData = *pdwBase + dwData;
        }

#ifdef _DEBUG
        pCode->m_dwCodeCount++;
#endif
    }
    return cBytes;
}

TUint8 TBitStream::DecodeXInt32(XInt32& xData, RPointerArray<TBitCode>& pBitCodes, XInt32* pxBase,
    TBool bReverse)
{
    TUint8 cBytes = 0;
    XInt32 xBase;
    if (pxBase != NULL)
        xBase = *pxBase;
    xData = 0;
    TInt dwData = 0;
    TBitCode* pCode = MatchCodeDecode(dwData, cBytes, pBitCodes);
    if (pCode != NULL)
    {
        if (pCode->m_cDataType == 'O')
            xData.SetRawData(dwData);
        else
        {
            if (pxBase != NULL)
            {
                if (bReverse)
                    xData = (TInt64) (xBase) - (TInt) dwData;
                else
                    xData = (TInt64) (xBase) + (TInt) dwData;
            }
            else
                xData = (TInt) dwData;
        }

#ifdef _DEBUG
        pCode->m_dwCodeCount++;
#endif
    }
    return cBytes;
}

//TUint8 CBitStream::WriteBOOL(TBool bValue)
//{
//	if(bValue)
//		return WriteDWORD(1, 1);
//	else
//		return WriteDWORD(0, 1);
//}

void TBitStream::DecodeAllMMPPrice(TInt NUM_OF_MMP, TGoods& goods, TInt nIndex)
{
    TInt POS_BITS = 4;
    if (NUM_OF_MMP == 10)
        POS_BITS = 5;
    if (goods.IsGZQH())
        POS_BITS = 2;

    TInt nPrice = goods.m_nPrice / goods.m_nPriceDivide;

    TInt nNumOfGap = ReadDWORD(2, ETrue);

    // Pbuy1 / Psell1
    //	TUint8 CBitStream::DecodeData(TInt& dwData, RPointerArray<TBitCode>& pBitCodes , TInt* pdwBase, TBool bReverse)
    //TInt dw = 0;
    TInt nEncodePrice = 0;
    DecodeData(nEncodePrice, BC_DYNA_PRICE_MMP, &nPrice, EFalse);

    TInt nBasePos = 0;
    if (nEncodePrice == nPrice + 999999)
    {
        nBasePos = NUM_OF_MMP;
        goods.m_pnMMP[nIndex + nBasePos] = nPrice * goods.m_nPriceDivide;
    }
    else
    {
        if (goods.m_bNumBuy == 0)
            nBasePos = NUM_OF_MMP;
        else
            nBasePos = NUM_OF_MMP - 1;
        goods.m_pnMMP[nIndex + nBasePos] = nEncodePrice * goods.m_nPriceDivide;
    }

    TInt nGap = 0;
    if (nNumOfGap == 1)
    {
        TInt nGapPos = ReadDWORD(POS_BITS, ETrue);
        nGap = (1 << nGapPos);
    }
    else if (nNumOfGap == 2)
    {
        nGap = ReadDWORD(goods.m_bNumBuy + goods.m_bNumSell - 1, ETrue);
        nGap <<= (NUM_OF_MMP - goods.m_bNumBuy);
    }

    for (TInt i = nBasePos - 1; i >= NUM_OF_MMP - goods.m_bNumBuy; i--)
    {
        if ((nGap & (1 << i)) != 0)
        {
            TInt adwMMPPrice = goods.m_pnMMP[nIndex + i + 1] / goods.m_nPriceDivide;
            DecodeData(goods.m_pnMMP[nIndex + i], BC_DYNA_PRICE_GAP, &adwMMPPrice, ETrue);
            goods.m_pnMMP[nIndex + i] *= goods.m_nPriceDivide;
        }
        else
        {
            goods.m_pnMMP[nIndex + i] = goods.m_pnMMP[nIndex + i + 1] - goods.m_nPriceDivide;
        }
    }

    for (TInt i = nBasePos; i < NUM_OF_MMP + goods.m_bNumSell - 1; i++)
    {
        if ((nGap & (1 << i)) != 0)
        {
            TInt adwMMPPrice = goods.m_pnMMP[nIndex + i] / goods.m_nPriceDivide;
            DecodeData(goods.m_pnMMP[nIndex + i + 1], BC_DYNA_PRICE_GAP, &adwMMPPrice, EFalse);
            goods.m_pnMMP[nIndex + i + 1] *= goods.m_nPriceDivide;
        }
        else
        {
            goods.m_pnMMP[nIndex + i + 1] = goods.m_pnMMP[nIndex + i] + goods.m_nPriceDivide;
        }
    }
}

void TBitStream::ExpandMMP(TGoods& goods, TUint8 bL2Encode)
{
    // mmp consts
    TInt NUM_OF_MMP = 5;
    TInt POS_BITS = 4;
    if (bL2Encode != 0)
    {
        NUM_OF_MMP = 10;
        POS_BITS = 5;
    }
    // mmp arrays
    TInt nIndex;
    if (bL2Encode == 0)
        nIndex = 5;
    else
        nIndex = 0;

    // NumBuy, NumSell
    TUint8 bNumBuySell = (TUint8) ReadDWORD(1, ETrue);
    if (bNumBuySell != 0)
    {
        goods.m_bNumBuy = (TUint8) ReadDWORD(POS_BITS - 1, ETrue);
        goods.m_bNumSell = (TUint8) ReadDWORD(POS_BITS - 1, ETrue);
    }
    else
    {
        goods.m_bNumBuy = (TUint8) NUM_OF_MMP;
        goods.m_bNumSell = (TUint8) NUM_OF_MMP;
    }
    // whole price array
    DecodeAllMMPPrice(NUM_OF_MMP, goods, nIndex);

    XInt32 xn;
    for (TInt i = NUM_OF_MMP - goods.m_bNumBuy; i < NUM_OF_MMP + goods.m_bNumSell; i++)
    {
        if (goods.IsGZQH())
        {
            DecodeXInt32(xn, BC_DYNA_QH_VOL_DIFF, NULL, EFalse);
        }
        else
        {
            DecodeXInt32(xn, BC_DYNA_VOL_DIFF, NULL, EFalse);
        }
        goods.m_pxMMPVol[nIndex + i] = xn;
    }
}

void TBitStream::ExpandMMP(TGoods& goods, TGoods& goodsOld, TUint8 bL2Encode)
{
    // mmp consts
    TInt NUM_OF_MMP = 5;
    TInt POS_BITS = 4;
    if (bL2Encode != 0)
    {
        NUM_OF_MMP = 10;
        POS_BITS = 5;
    }

    TInt nArraySize = NUM_OF_MMP * 2;

    TInt nIndex = 0;
    TUint8 bNumLastBuy = goodsOld.m_bNumBuy;
    TUint8 bNumLastSell = goodsOld.m_bNumSell;

    if (bL2Encode == 0)
    {
        nIndex = 5;
        if (bNumLastBuy > NUM_OF_MMP)
            bNumLastBuy = (TUint8) NUM_OF_MMP;
        if (bNumLastSell > NUM_OF_MMP)
            bNumLastSell = (TUint8) NUM_OF_MMP;
    }

    TUint8 MMP_NOCHANGE = 0; // 00
    TUint8 MMP_VCHANGE = 1; // 01
    TUint8 MMP_PVCHANGE = 2; // 10
    TUint8 MMP_PPVCHANGE = 3; // 11, encode whole price array

    TUint8 bPVchange = (TUint8) ReadDWORD(2, ETrue);
    if (bPVchange == MMP_NOCHANGE)
    {
        for (TInt i = 0; i < nArraySize; i++)
        {
            goods.m_pnMMP[nIndex + i] = goodsOld.m_pnMMP[nIndex + i];
            goods.m_pxMMPVol[nIndex + i] = goodsOld.m_pxMMPVol[nIndex + i];
        }
        goods.m_bNumBuy = bNumLastBuy;
        goods.m_bNumSell = bNumLastSell;
    }
    else
    {
        TInt64 plMMPVol[20];
        for (TInt i = 0; i < 20; i++)
            plMMPVol[i] = 0;

        if (bPVchange == MMP_VCHANGE)
        {
            for (TInt i = 0; i < nArraySize; i++)
                goods.m_pnMMP[nIndex + i] = goodsOld.m_pnMMP[nIndex + i];
            goods.m_bNumBuy = bNumLastBuy;
            goods.m_bNumSell = bNumLastSell;
        }
        else // pv/ppv
        {
            TUint8 bNumBuySell = (TUint8) ReadDWORD(1, ETrue);
            if (bNumBuySell != 0)
            {
                goods.m_bNumBuy = (TUint8) ReadDWORD(POS_BITS - 1, ETrue);
                goods.m_bNumSell = (TUint8) ReadDWORD(POS_BITS - 1, ETrue);
            }
            else
            {
                goods.m_bNumBuy = (TUint8) NUM_OF_MMP;
                goods.m_bNumSell = (TUint8) NUM_OF_MMP;
            }

            if (bPVchange == MMP_PVCHANGE)
            {
                TInt nModCode = ReadDWORD(4, ETrue);
                if (nModCode < 8) // special case, just insert one price
                {
                    TInt nInsPos = -1;
                    TInt nDelPos = -1;

                    if (nModCode == 0) // ins buy5/10, del sell 5/10
                    {
                        nInsPos = 0;
                        nDelPos = nArraySize - 1;
                    }
                    else if (nModCode == 1) // ins sell1,   del sell 5/10
                    {
                        nInsPos = NUM_OF_MMP;
                        nDelPos = nArraySize - 1;
                    }
                    else if (nModCode == 2) // ins buy5/10,   del buy1
                    {
                        nInsPos = 0;
                        nDelPos = NUM_OF_MMP - 1;
                    }
                    else if (nModCode == 3) // del buy5/10,   ins buy1
                    {
                        nInsPos = NUM_OF_MMP - 1;
                        nDelPos = 0;
                    }
                    else if (nModCode == 4) // del sell1,   ins sell5/10
                    {
                        nInsPos = nArraySize - 1;
                        nDelPos = NUM_OF_MMP;
                    }
                    else if (nModCode == 5) // del buy5/10,   ins sell5/10
                    {
                        nInsPos = nArraySize - 1;
                        nDelPos = 0;
                    }

                    for (TInt i = 0; i < nArraySize; i++)
                        goods.m_pnMMP[nIndex + i] = goodsOld.m_pnMMP[nIndex + i];
                    if (nInsPos < nDelPos)
                    {
                        //								for (int i=nDelPos+1; i>nInsPos; i--)
                        //									goods.m_pnMMP[nIndex+i] = goods.m_pnMMP[nIndex+i-1];
                        for (TInt i = nInsPos; i < nDelPos; i++)
                            goods.m_pnMMP[nIndex + i + 1] = goodsOld.m_pnMMP[nIndex + i];
                    }
                    else
                    {
                        for (TInt i = nDelPos; i < nInsPos; i++)
                            goods.m_pnMMP[nIndex + i] = goodsOld.m_pnMMP[nIndex + i + 1];
                    }
                    TInt nPriceInsGap = 0;
                    DecodeData(nPriceInsGap, BC_DYNA_PRICE_INS, NULL, EFalse);
                    if (nPriceInsGap == 999999)
                        goods.m_pnMMP[nIndex + nInsPos] = 0;
                    else
                    {
                        if (nInsPos > 0)
                            goods.m_pnMMP[nIndex + nInsPos] = goods.m_pnMMP[nIndex + nInsPos - 1]
                                + nPriceInsGap * goods.m_nPriceDivide;
                        else
                            goods.m_pnMMP[nIndex] = goods.m_pnMMP[nIndex + 1] - nPriceInsGap
                                * goods.m_nPriceDivide;
                    }

                    for (TInt i = NUM_OF_MMP + goods.m_bNumSell; i < nArraySize; i++)
                        goods.m_pnMMP[nIndex + i] = 0;
                }
                else
                {
                    TInt nNumOfPChange = nModCode - 8;
                    if (nNumOfPChange == 0)
                    {
                        for (TInt i = 0; i < NUM_OF_MMP + goods.m_bNumSell; i++)
                            goods.m_pnMMP[nIndex + i] = goodsOld.m_pnMMP[nIndex + i];
                    }
                    else
                    {
                        TUint8 MOD_INSERT = 0; // 0
                        TUint8 MOD_DELETE = 1; // 1

                        TInt nChngPos = 0;

                        TInt nPricePos = ReadDWORD(POS_BITS, ETrue);
                        TInt nPriceModType = ReadDWORD(1, ETrue);
                        TInt nPriceInsGap = 0;
                        if (nPriceModType == MOD_INSERT)
                            DecodeData(nPriceInsGap, BC_DYNA_PRICE_INS, NULL, EFalse);

                        TInt nPos = 0;
                        TInt nLastPos = 0;

                        TInt nTop = NUM_OF_MMP + goods.m_bNumSell;
                        TInt nLastTop = NUM_OF_MMP + bNumLastSell;

                        while (nPos < nTop)
                        {
                            TBool bChange = EFalse;

                            if (nPricePos == nLastPos && nPriceModType == MOD_DELETE)
                            {
                                nLastPos++;
                                bChange = ETrue;
                            }
                            else if (nPricePos == nPos && nPriceModType == MOD_INSERT)
                            {
                                if (nPriceInsGap == 999999)
                                    goods.m_pnMMP[nIndex + nPos] = 0;
                                else
                                {
                                    if (nPos > 0)
                                        goods.m_pnMMP[nIndex + nPos] = goods.m_pnMMP[nIndex + nPos
                                            - 1] + nPriceInsGap * goods.m_nPriceDivide;
                                    else
                                        goods.m_pnMMP[nIndex] = goods.m_nPrice - nPriceInsGap
                                            * goods.m_nPriceDivide;
                                }

                                nPos++;

                                bChange = ETrue;
                            }
                            else
                            {
                                if (nLastPos < nLastTop)
                                    goods.m_pnMMP[nIndex + nPos] = goodsOld.m_pnMMP[nIndex
                                        + nLastPos];

                                nPos++;
                                nLastPos++;
                            }

                            if (bChange)
                            {
                                nChngPos++;
                                if (nChngPos < nNumOfPChange) // read next one
                                {
                                    nPricePos = ReadDWORD(POS_BITS, ETrue);
                                    nPriceModType = ReadDWORD(1, ETrue);
                                    nPriceInsGap = 0;
                                    if (nPriceModType == MOD_INSERT)
                                        DecodeData(nPriceInsGap, BC_DYNA_PRICE_INS, NULL, EFalse);
                                }
                                else
                                    // change list end
                                    nPricePos = -1;
                            }
                        }
                    }// nNumOfPChange > 0
                }// decode price change one by one
            }// cPVchange == MMP_PVCHANGE
            else // cPVchange == MMP_PPVCHANGE
            {
                DecodeAllMMPPrice(NUM_OF_MMP, goods, nIndex);
            }// cPVchange == MMP_PPVCHANGE
        }// p changed

        // volume decoding
        if (bNumLastBuy > 0 || bNumLastSell > 0)
        {
            TInt nPos = NUM_OF_MMP - goods.m_bNumBuy;
            TInt nLastPos = NUM_OF_MMP - bNumLastBuy;

            while (nPos < NUM_OF_MMP + goods.m_bNumSell && nLastPos < NUM_OF_MMP + bNumLastSell)
            {
                if (goods.m_pnMMP[nIndex + nPos] == goodsOld.m_pnMMP[nIndex + nLastPos])
                {
                    if (nPos < NUM_OF_MMP && nLastPos < NUM_OF_MMP || nPos >= NUM_OF_MMP
                        && nLastPos >= NUM_OF_MMP)
                        plMMPVol[nIndex + nPos] = goodsOld.m_pxMMPVol[nIndex + nLastPos].GetValue();

                    nPos++;
                    nLastPos++;
                }
                else if (goods.m_pnMMP[nIndex + nPos] > goodsOld.m_pnMMP[nIndex + nLastPos]) // delete
                    nLastPos++;
                else
                    // pnMMP[nPos] < pnLastMMPPrice[nLastPos] // insert
                    nPos++;
            }

            if (goods.m_pnMMP[nIndex + NUM_OF_MMP - 1] == goods.m_nPrice)
                plMMPVol[nIndex + NUM_OF_MMP - 1] = plMMPVol[nIndex + NUM_OF_MMP - 1]
                    - (goods.m_xVolume.GetValue() - goodsOld.m_xVolume.GetValue());
            else if (goods.m_pnMMP[nIndex + NUM_OF_MMP] == goods.m_nPrice)
                plMMPVol[nIndex + NUM_OF_MMP] = plMMPVol[nIndex + NUM_OF_MMP]
                    - (goods.m_xVolume.GetValue() - goodsOld.m_xVolume.GetValue());
        }

        XInt32 xV;

        TUint8 bMaxVChange = (TUint8) ReadDWORD(1, ETrue);
        if (bMaxVChange == 0)
        {
            TInt nNumOfVChange = ReadDWORD(2, ETrue);
            for (TInt i = 0; i < nNumOfVChange; i++)
            {
                TInt nVPos = ReadDWORD(POS_BITS, ETrue);
                if (goods.IsGZQH())
                {
                    DecodeXInt32(xV, BC_DYNA_QH_VOL_DIFFS, NULL, EFalse);
                }
                else
                {
                    DecodeXInt32(xV, BC_DYNA_VOL_DIFFS, NULL, EFalse);
                }
                plMMPVol[nIndex + nVPos] = plMMPVol[nIndex + nVPos] + xV.GetValue();
            }
        }
        else
        {
            TInt nVolChange = ReadDWORD(goods.m_bNumBuy + goods.m_bNumSell, ETrue);
            nVolChange <<= (NUM_OF_MMP - goods.m_bNumBuy);

            for (TInt i = 0; i < nArraySize; i++)
            {
                if ((nVolChange & (1 << i)) != 0)
                {
                    if (goods.IsGZQH())
                    {
                        DecodeXInt32(xV, BC_DYNA_QH_VOL_DIFFS, NULL, EFalse);
                    }
                    else
                    {
                        DecodeXInt32(xV, BC_DYNA_VOL_DIFFS, NULL, EFalse);
                    }
                    plMMPVol[nIndex + i] = plMMPVol[nIndex + i] + xV.GetValue();
                }
            }
        }

        for (TInt i = 0; i < 20; i++)
            goods.m_pxMMPVol[i] = plMMPVol[i];
    }
}

void TBitStream::ExpandVirtualMMP(TGoods& goods)
{
    TInt n = goods.m_nPrice / goods.m_nPriceDivide;
    DecodeData(goods.m_pnMMP[9], BC_DYNA_PRICE_DIFFS, &n, EFalse);
    goods.m_pnMMP[9] *= goods.m_nPriceDivide;
    goods.m_pnMMP[10] = goods.m_pnMMP[9];

    DecodeXInt32(goods.m_pxMMPVol[9], BC_DYNA_VOL, NULL, EFalse);
    goods.m_pxMMPVol[10] = goods.m_pxMMPVol[9];

    TUint8 b8 = (TUint8) ReadDWORD(1, ETrue);
    if (b8 != 0)
        DecodeXInt32(goods.m_pxMMPVol[8], BC_DYNA_VOL, NULL, EFalse);
    else
        DecodeXInt32(goods.m_pxMMPVol[11], BC_DYNA_VOL, NULL, EFalse);

    goods.m_bVirtual = 1;
}

void TBitStream::ExpandVirtualMMP(TGoods& goods, TGoods& goodsOld)
{
    TInt n = goodsOld.m_pnMMP[9] / goods.m_nPriceDivide;
    DecodeData(goods.m_pnMMP[9], BC_DYNA_PRICE_DIFFS, &n, EFalse);
    goods.m_pnMMP[9] *= goods.m_nPriceDivide;
    goods.m_pnMMP[10] = goods.m_pnMMP[9];

    DecodeXInt32(goods.m_pxMMPVol[9], BC_DYNA_VOL_DIFF, &goodsOld.m_pxMMPVol[9], EFalse);
    goods.m_pxMMPVol[10] = goods.m_pxMMPVol[9];

    TUint8 b8 = (TUint8) ReadDWORD(1, ETrue);
    if (b8 != 0)
    {
        DecodeXInt32(goods.m_pxMMPVol[8], BC_DYNA_VOL_DIFF, &goodsOld.m_pxMMPVol[8], EFalse);
        goods.m_pxMMPVol[11].SetRawData(0);
    }
    else
    {
        DecodeXInt32(goods.m_pxMMPVol[11], BC_DYNA_VOL_DIFF, &goodsOld.m_pxMMPVol[11], EFalse);
        goods.m_pxMMPVol[8].SetRawData(0);
    }
    goods.m_bVirtual = 1;
}
